<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>加减计数器</title>
</head>

<body>
    <div id="app">
        <div class="input-num">
            <button v-on:click="sub">-</button>
            <span>{{num}}</span>
            <button v-on:click="add">+</button>
            <h1 style="color: green;" v-if="isShow">错误</h1>
        </div>
    </div>
    <script src="./js/vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                num:1,
                isShow:false
            },
            methods:{
                add(){
                    this.num++;
                    this.show();
                },
                sub(){
                    this.num--;
                    this.show();
                },
                show(){
                    if(this.num<=1 || this.num>=10){     
                        this.isShow=true;
                    }else{
                        this.isShow=false;
                    }                  
                }
            }
        })
    </script>
</body>

</html>